package com.mc.mcgoweb.aop;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Created By liuxiaoming
 * @CreateTime 2017/12/8 上午10:18
 **/
@Aspect
@Component
//多个AOP拦截的顺序，数值越小，拦截越早
@Order(1)
public class LoginAop {

    @Pointcut("execution(public * com.mc.mcgoweb.*Controller.*(..))")
    public void verify(){}

    @Before("verify()")
    public void doVerify(JoinPoint joinPoint){
        ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        Object[] args = joinPoint.getArgs();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("1","22222222222222");//类似于map

        Signature signature = joinPoint.getSignature();
//
//        //查询cookie
//        Cookie com.mc.common.cookie = CookieUtil.get(request, CookieConstant.ACCESS_TOKEN);
//        if(com.mc.common.cookie == null){
//            log.warn("【登陆校验】Cookie中查不到token");
//            throw new SellerAuthorizeException();
//        }
//
//        //从Redis中查询
//        String tokenValue = redisTemplate.opsForValue().get(String.format(RedisConstant.TOKEN_PREFIX,com.mc.common.cookie.getValue()));
//        if(StringUtils.isEmpty(tokenValue)){
//            log.warn("【登陆校验】Redis中查不到token");
//            throw new SellerAuthorizeException();
//        }
    }
}